package demo1;

import com.sun.jdi.connect.Connector;

public class TestHeap {
    public int useSize;
    public int[] elam;
    public TestHeap(){
        this.elam = new int[10];
    }
    public void init(int[] array){
        for (int i = 0; i < elam.length; i++) {
            elam[i] = array[i];
            useSize++;
        }
    }
    public void creatHeap(int parent,int useSize){
        int child = parent * 2 + 1;
        while(child < useSize){
            if(child + 1 < useSize && elam[child] < elam[child + 1]){
                child++;
            }
            if(elam[child] > elam[parent]){
                swap(elam,child,parent);
                parent = child;
                child = parent * 2 + 1;
            }else {
                break;
            }
        }
    }
    private void swap(int[] elam,int child,int parent){
        int tmp = elam[child];
        elam[child] = elam[parent];
        elam[parent] = tmp;
    }
}
